package com.bkaptech;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class Android4UReceiver extends BroadcastReceiver {

	private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    private static final String TAG = "SMSBroadcastReceiver";
    
	@Override
	public void onReceive(Context context, Intent intent) {
		if(intent.getAction().equals(SMS_RECEIVED)){
			Bundle bundle = intent.getExtras();
            if (bundle != null) {
                Object[] smsMessage = (Object[])bundle.get("pdus");
                final SmsMessage[] messages = new SmsMessage[smsMessage.length];
                for (int i = 0; i < smsMessage.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[])smsMessage[i]);
                }
                if (messages.length > -1) {
                    Log.i(TAG, "Message recieved: " + messages[0].getMessageBody());
                    // show first message
            		Toast toast = Toast.makeText(context, "Received SMS: " + messages[0].getMessageBody(), Toast.LENGTH_LONG);
            		toast.show();
                }
            }
		}

		
			
	}

}
